/*轮播*/
    $('#banner ul li').clone().appendTo('#banner ul');
    var index = 0;
    var banner = $('#banner');
    var bannerUl = $('#banner ul');
    var bannerOl_li = $('#banner ol li');
    var bannerUl_li = $('#banner ul li');
    /*轮播*/
    bannerOl_li.click(function () {
        index = $(this).index();
        $(this).addClass('on').siblings().removeClass('on');
        bannerUl.stop().animate({"left": -index * bannerUl_li.width()}, 1000)
    });
    /*轮播函数*/
    function carousel() {
        index++;
        if (index == bannerUl_li.length) {
            index = 1;
            bannerUl.css("left", 0);
        }
        bannerUl.animate({"left": -index * bannerUl_li.width()}, 1000);
        if (index == bannerUl_li.length - 1) {
            bannerOl_li.eq(0).addClass('on').siblings().removeClass('on');
        }
        else {
            bannerOl_li.eq(index).addClass('on').siblings().removeClass('on');
        }
    }
    /*设置定时*/
    var Timer = setInterval('carousel()', 1800);
    banner.hover(function () {
        clearInterval(Timer);
    }, function () {
        Timer = setInterval('carousel()', 1800);
    });

$(function(){
    var main=$('#main');
    var times=new Date();
    var timeSecond=Math.floor(times.getTime()/1000+172800);
    var timeArr=LsyStorage.getItem('time');
    timeArr=timeArr?timeArr:[];
    timeArr.push(timeSecond);
    if(timeArr.length>3){
        timeArr.pop(timeSecond);
    }
    LsyStorage.setItem("time",timeArr);
    var i=0;
    var slideBarLi=$('#sidebar_left li');
    var bodyHtml=$('html,body');
    loginTest();
    countDown();
    sideClick(0,'.bursting_goods');
    sideClick(1,'.hot_goods');
    sideClick(2,'#high');
    sideClick(3,'#bass');
    sideClick(4,'#high_area');
    sideClick(5,'#bass_area');
    sideClick(6,'.lovely');
    function sideClick(num,Event){
        var goodsList=slideBarLi.eq(num);
        goodsList.click(function(){
            goodsList.addClass('on').siblings().removeClass('on');
            var top=main.find(Event).offset().top;
            bodyHtml.animate({scrollTop:top},500);
        })
    }
    function scrollChange(event1,event2,num,topBody){
        var height=main.find(event1).height();
        var top1=main.find(event1).offset().top-height/2;
        var top2=main.find(event2).offset().top+height/2;
        var goodsLi=slideBarLi.eq(num);
        if(top1<=topBody && topBody<top2){
            goodsLi.addClass('on').siblings().removeClass('on');
        }
    }
    /*倒计时*/
    function countDown(){
        var time=$('.time');
        var day=time.find('b');
        var hour=time.find('i');
        var minute=time.find('span');
        var second=time.find('s');
        var i= 0,days= 0,hours= 0,minutes=0,seconds= 0,newSeconds= 0,newTime=0;
        setInterval(function(){
            newTime=new Date();
            newSeconds=Math.floor(newTime.getTime()/1000);
            if(timeArr[0]){
                i=timeArr[0]-newSeconds;
            }else{
                i=172800;
            }
            if(i<0){
                timeArr.unshift(newSeconds+172800);
            }
            days=Math.floor(i/(60*60*24));
            hours=Math.floor(i%(60*60*24)/(60*60));
            minutes=Math.floor(i%(60*60*24)%(60*60)/60);
            seconds=Math.floor(i%(60*60*24)%(60*60)%60);
            day.text(days);
            hour.text(hours);
            minute.text(minutes);
            second.text(seconds);
        },1000)
    }
    window.onscroll = function () {
        var burstingGoodsTop=main.find('.bursting_goods').offset().top;
        var burstingGoodsHeight=main.find('.bursting_goods').height();
        var lovelyTop=main.find('.lovely').offset().top;
        var lovelyHeight=main.find('.bursting_goods').height();
        var top = $(document).scrollTop();
        if(top<620){
            $('#sidebar_right').css("display","none");
        }else{
            $('#sidebar_right').css("display","block");
        }
        if(top<burstingGoodsTop-burstingGoodsHeight/2 || top>lovelyTop+lovelyHeight/2){
            $('#sidebar_left').css("display","none");
        }else{
            $('#sidebar_left').css("display","block");
        }
        scrollChange('.bursting_goods','.hot_goods','0',top);
        scrollChange('.hot_goods','#high','1',top);
        scrollChange('#high','#bass','2',top);
        scrollChange('#bass','#high_area','3',top);
        scrollChange('#high_area','#bass_area','4',top);
        scrollChange('#bass_area','.lovely','5',top);
        scrollChange('.lovely','.foot','6',top);
    };
});

